package com.woniuxy.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RbacManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @Author: 马宇航
 * @Do: Controller
 * @DateTime: 22/05/16/0016 上午 11:49
 * @Component: 成都蜗牛学苑
 **/
@RestController
@CrossOrigin
@RequestMapping("/rbacManager")
public class MyRbacController {
    @Autowired
    RbacManagerService rbacManagerService;
    /**
     * 查询列表
     * ChangeLog : 1. 创建 (22/05/19/0019 下午 3:09 [马宇航]);
     * @param currentPage 当前是第几页
     * @param pageSize  每页显示多少条
     * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    */
    @GetMapping("/findAll/{currentPage}/{pageSize}")
    public ResponseEntity findAll(@PathVariable int currentPage,@PathVariable int pageSize){
        PageHelper.startPage(currentPage,pageSize);
        List<Map<String, Object>> all = rbacManagerService.findAll();
        PageInfo pageInfo = new PageInfo(all);
        return new ResponseEntity().setData(pageInfo);
    }
    @DeleteMapping("/manager/{id}")
    public int deleteOne(@PathVariable("id") int id){
        return rbacManagerService.deleteOne(id);
    }
    @PostMapping("/manager")
    public int addOne(@RequestBody RbacManager rbacManager){
        return rbacManagerService.addOne(rbacManager);
    }
    @PutMapping("/manager")
    public int updateOne(@RequestBody RbacManager rbacManager){
        return rbacManagerService.updataOne(rbacManager);
    }
}
